<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>02数据代理</title>
</head>
<body>
  <script>
    // 数据代理：通过一个对象，代理对另一个对象中的属性进行操作(读/写)
    let obj = {
      name: 'dog'
    }

    let per = {
      age: 2
    }

    Object.defineProperty(per, 'name', {
      get() {
        return obj.name
      },
      set(val) {
        obj.name = val
      }
    })
  </script>
</body>
</html>